<?php

	class cct_member extends ctl_member
	{
		function uploadImg($order_id)
		{
			$this->pagedata['order_id'] = $order_id;
			$this->_output();
		}

		function toUploadImg()
		{
			$this->begin($this->system->mkUrl('member','orderdetail',array($_POST['order_id'])));
			if ($filePath = $this->uploadFile($_FILES))
			{
				$_POST['picPath'] = $filePath;
			}
		}

		function uploadFile($aData)
		{
			$uploadPath = 'home/upload/pic/';
			if (!is_dir(UPLOAD_FILE_PATH))
			{
				mkdir_p(BASE_DIR.$uploadPath,0777);
			}
			if ($aData['file']['error'] > 0)
			{
				trigger_error('上传出现错误: '.$aData['file']['error'],E_USER_ERROR);
				exit;
			}
			else
			{
				$fileExt = substr($aData['file']['name'],strrpos($aData['file']['name'],'.'));	//取文件的扩展名
				$newFile = $uploadPath.date('YmdHis').$fileExt;	//得到新的文件名(根据当前的时间)
				if (is_uploaded_file($aData['file']['tmp_name']))
				{
					if (is_file(BASE_DIR.$newFile))
					{
						trigger_error($aData['file']['name'].'该文件已经存在!',E_USER_ERROR);
						return false;
					}
					if(move_uploaded_file($aData['file']['tmp_name'],BASE_DIR.$newFile)) return $newFile;
					if(copy($aData['file']['tmp_name'],BASE_DIR.$newFile))	return $newFile;
				}
			}
		}

		function imgDownload($packet_id)
		{
			header("Content-type:application/octet-stream;charset=utf-8");
			header("Content-Type: application/force-download");
			$oPacket = $this->system->loadModel('content/packet');
			$row = $oPacket->getFieldById($packet_id,array('packet_href','packet_name'));
			$fileExt = substr($row['packet_href'],strrpos($row['packet_href'],'.'));
			$oCharset = $this->system->loadModel('utility/charset');
			$fileName = $oCharset->utf2local($row['packet_name'].$fileExt,'zh');
			header("Content-Disposition:attachment;filename=".$fileName);
			$content = file_get_contents(BASE_DIR.$row['packet_href']);
			echo $content;
		}
	}
?>